package com.pay.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.util.Properties;

/**
 * Created by lenovo on 2016/7/5.
 */
public class PropertiesFactoryHelper {
    private Logger log = LoggerFactory.getLogger(getClass());
    /**
     * 私有的属性防止外部引用
     */
    private static PropertiesFactoryHelper _instance = null;
    private Properties properties = new Properties();
    /**
     * 私有的默认构造函数，防止使用构造函数进行实例化
     */
    private PropertiesFactoryHelper() {
        try {
            InputStream inputStream = this.getClass().getResourceAsStream(
                    "/config/config.properties");
            properties.load(inputStream);
            if (inputStream != null)
                inputStream.close();
        } catch (Exception e) {
            log.info("file not found",e);
        }
    }

    /**
     * 单例静态工厂方法，同步防止多线程环境同时执行
     */
    synchronized public static PropertiesFactoryHelper getInstance() {
        if (_instance == null) {
            _instance = new PropertiesFactoryHelper();
        }
        return _instance;
    }
    /**
     * 读取配置信息key - value
     */
    public String getConfig(String key) {
        return properties.getProperty(key);
    }
}
